/**
 * 
 */
package fanalg;

/**
 * @author Tomasz Werszko
 */
public enum LogicSystem {
	TRUE,
	FALSE,
	X,
	D,
	notD;
	
	public static LogicSystem OR(LogicSystem arg1, LogicSystem arg2){
		if(arg1 == arg2){
			return arg1;
		}
		if(arg1 == FALSE){
			return arg2;
		}
		if(arg2 == FALSE){
			return arg1;
		}
		if(arg1 == TRUE || arg2 == TRUE){
			return TRUE;
		}
		if(arg1 == X || arg2 == X){
			return X;
		}	
		return TRUE;
		
	}
	public static LogicSystem AND(LogicSystem arg1, LogicSystem arg2){
		if(arg1 == FALSE || arg2 == FALSE){
			return FALSE;
		}
		if(arg1 == TRUE){
			return arg2;
		}
		if(arg2 == TRUE){
			return arg1;
		}
		if(arg1 == X || arg2 == X){
			return X;
		}
		if(arg1 == arg2){
			return arg1;
		}
		return FALSE;
	}
	public static LogicSystem NOT(LogicSystem arg){
		if(arg == FALSE){
			return TRUE;
		}
		if(arg == TRUE){
			return FALSE;
		}
		if(arg == X){
			return X;
		}
		if(arg == D){
			return notD;
		}
		return D;
	}
	public static LogicSystem NAND(LogicSystem arg1, LogicSystem arg2){
		return NOT(AND(arg1,arg2));
	}
	public static LogicSystem NOR(LogicSystem arg1, LogicSystem arg2){
		return NOT(OR(arg1, arg2));
	}
	public static LogicSystem fromBoolean(boolean b){
		if(b == true){
			return TRUE;
		}else{
			return FALSE;
		}
	}
	public static LogicSystem fromInteger(int i){
		if(i == 1){
			return TRUE;
		}else if(i == 0){
			return FALSE;
		}else{
			return X;
		}
	}
}
